package csc.daonjpa.java.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import csc.daonjpa.java.dao.AccountDAO;
import csc.daonjpa.java.dao.CardDAO;
import csc.daonjpa.java.dao.CustomerDAO;
import csc.daonjpa.java.dao.TargetAccountDAO;
import csc.daonjpa.java.dao.TransferTransactionDAO;
import csc.daonjpa.java.domain.Account;
import csc.daonjpa.java.domain.Card;
import csc.daonjpa.java.domain.Customer;
import csc.daonjpa.java.domain.TargetAccount;
import csc.daonjpa.java.domain.TransferTransaction;

/**
 * Business service class.
 * 
 * @author tnguyen256
 *
 */
@Service
public class BankService {

	// Account related methods
	private AccountDAO accountDAO;

	public AccountDAO getAccountDAO() {
		return accountDAO;
	}

	@Autowired
	public void setAccountDAO(AccountDAO accountDAO) {
		this.accountDAO = accountDAO;
	}

	public void addAccount(Account account) {
		accountDAO.addAccount(account);
	}

	public List<Account> getAccounts() {
		return accountDAO.getAccounts();
	}

	public List<Account> getAccountsByCustomerId(String custLoginId) {
		return accountDAO.getAccountsByCustomerId(custLoginId);
	}

	public Account getAccountByAccNumber(String accountNumber) {
		return accountDAO.getAccountByAccNumber(accountNumber);
	}
	
	public Account getAccountByAccId(int id) {
		return accountDAO.getAccountByAccId(id);
	}

	// Customer related methods
	private CustomerDAO customerDAO;

	public CustomerDAO getCustomerDAO() {
		return customerDAO;
	}

	@Autowired
	public void setCustomerDAO(CustomerDAO customerDAO) {
		this.customerDAO = customerDAO;
	}

	public boolean addCustomer(Customer customer) {
		return customerDAO.addCustomer(customer);
	}

	public List<Customer> getCustomers() {
		return customerDAO.getCustomers();
	}

	public Customer getCustomerByLoginInfo(String custId, String password) {
		return customerDAO.getCustomerByLoginInfo(custId, password);
	}

	public int changeCustomerPassword(String loginid, String newPassword) {
		return customerDAO.changeCustomerPassword(loginid, newPassword);
	}

	public int updateCustomerInfo(Customer customer) {
		return customerDAO.updateCustomerInfo(customer);
	}

	// Card related methods
	private CardDAO cardDAO;

	public CardDAO getCardDAO() {
		return cardDAO;
	}

	@Autowired
	public void setCardDAO(CardDAO cardDAO) {
		this.cardDAO = cardDAO;
	}

	public void addCard(Card card) {
		cardDAO.addCard(card);
	}
	
	public Card getCardByTypeAndName(String cardBank, String cardType) {
		return cardDAO.getCardByTypeAndName(cardBank, cardType);
	}

	public List<Card> getCards() {
		return cardDAO.getCards();
	}

	public List<Card> getCardsByCustomerId(String custLoginId) {
		return cardDAO.getCardsByCustomerId(custLoginId);
	}

	// Transfer transaction related methods
	private TransferTransactionDAO transferTransactionDAO;

	public TransferTransactionDAO getTransferTransactionDAO() {
		return transferTransactionDAO;
	}

	@Autowired
	public void setTransferTransactionDAO(
			TransferTransactionDAO transferTransactionDAO) {
		this.transferTransactionDAO = transferTransactionDAO;
	}

	public List<TransferTransaction> getTransferTransactions() {
		return transferTransactionDAO.getTransferTransactions();
	}

	public boolean addTransferTransation(TransferTransaction transaction) {
		return transferTransactionDAO.addTransferTransation(transaction);
	}

	public List<TransferTransaction> getTransferTransactionBySourceId(Integer id) {
		return transferTransactionDAO.getTransferTransactionBySourceId(id);
	}

	// Target Account related methods
	private TargetAccountDAO targetAccountDAO;

	public List<TargetAccount> getAllTargetAccounts(){
		return targetAccountDAO.getAllTargetAccounts();
	}
	
	public TargetAccount getTargetAccountByAccId(int id) {
		return targetAccountDAO.getTargetAccountByAccId(id);
	}
	
	public TargetAccount getTargetAccountByAccNum(String accNum) {
		return targetAccountDAO.getTargetAccountByAccNum(accNum);
	}

	public TargetAccountDAO getTargetAccountDAO() {
		return targetAccountDAO;
	}

	@Autowired
	public void setTargetAccountDAO(TargetAccountDAO targetAccountDAO) {
		this.targetAccountDAO = targetAccountDAO;
	}
	
	public void mergeAccount(Account account){
		accountDAO.mergeAccount(account);
	 }


}
